package com.dyw.Day30;




import java.util.ArrayList;

/**
 * @author Devil
 * @create 2022-04-07 23:46
 */
public class demo01 {
    public static void main(String[] args) {
        ListNode listNode = new ListNode(2, new ListNode(1));
        ListNode listNode1 = new ListNode(2, listNode);
        ListNode listNode2 = new ListNode(1, listNode1);

        System.out.println(listNode2.val+":"+listNode2.next.val);
        System.out.println(listNode2.next.next.val+":"+listNode2.next.next.next.val);
        boolean palindrome = new demo01().isPalindrome(listNode2);
        System.out.println(palindrome);
    }
    public boolean isPalindrome(ListNode head) {
        if(head==null){
            return true;
        }
        ArrayList<Integer> list = new ArrayList<>();
        while(head!=null){
            list.add(head.val);
            head = head.next;
        }
        for (int i = 0; i < list.size()/2; i++) {
            if(list.get(i)!=list.get(list.size()-1-i)){
                return false;
            }
        }
        return true;
    }
}
class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}